#pragma once

#include "Types.h"



namespace MemMgr
{
	class Chunk2
	{
		friend class FixedSizeAllocator2;

		typedef AtomSizeU BlockData;
		typedef AtomSizeU* BlockDataPtr;
		typedef T_U16 BlockCounter;
		typedef BlockCounter* BlockCounterPtr;

		void Init(const size_t iBlockSize, const BlockCounter iNnumBlocks);
		void* Allocate(const size_t iBlockSize);
		void Deallocate(void* iPtr, const size_t iBlockSize);
		void Release(void);

		inline bool HasBlock(void * iPtr, const size_t iChunkLength) const;
		inline bool HasAvailableBlocks(const size_t iNumBlocks) const;
		inline bool IsFull(void) const;

		static const BlockCounter MAX_NUM_BLOCKS = ~0;

		BlockDataPtr mData;
		//size_t mBlockSize;
		BlockCounter mFirstAvailableBlock;
		BlockCounter mNumAvailableBlocks;
	};



	inline bool Chunk2::HasBlock(void * iPtr, size_t iChunkLength) const
	{
		return (iPtr >= mData) && (iPtr < mData + iChunkLength);
	}



	inline bool Chunk2::HasAvailableBlocks(const size_t iNumBlocks) const
	{
		return (mNumAvailableBlocks == iNumBlocks);
	}



	inline bool Chunk2::IsFull(void) const
	{
		return (0 == mNumAvailableBlocks);
	}

};